import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class MainPage extends StatelessWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<MainLogic>();
    final state = Get.find<MainLogic>().state;
    return Scaffold(
      backgroundColor: const Color(0xffF3F6F9),
      body: Obx(() {
        return PageView(
          controller: logic.pageController,
          onPageChanged: (i) {
            state.currentIndex.value = i;
          },
          children: state.pages.map((e) => e.page).toList(),
        );
      }),
      bottomNavigationBar: Obx(() {
        return Container(
          color: Colors.white,
          child: BottomNavigationBar(
            items: state.pages.map((e) => e.bottom).toList(),
            currentIndex: state.currentIndex.value,
            unselectedItemColor: Colors.grey,
            type: BottomNavigationBarType.fixed,
            onTap: logic.changePageTo,
          ),
        );
      }),
    );
  }
}
